﻿namespace RotovapPlatform.Domain.Equipment.Device.Motors.Dto;

/// <summary>
/// 电机状态数据传输对象
/// </summary>
public class MotorStatus
{
	/// <summary>
	/// 伺服报警 (Bit1 ALM)
	/// </summary>
	public bool ServoAlarm { get; set; }

	/// <summary>
	/// 正向极限 (Bit5 PEL)
	/// </summary>
	public bool ForwardLimit { get; set; }

	/// <summary>
	/// 负向极限 (Bit6 MEL)
	/// </summary>
	public bool ReverseLimit { get; set; }

	/// <summary>
	/// 使能 (Bit9 SVON)
	/// </summary>
	public bool Enabled { get; set; }

	/// <summary>
	/// 运动 (Bit10 MOVE)
	/// </summary>
	public bool Running { get; set; }

	/// <summary>
	/// 输入点 (Bit11 INP)
	/// </summary>
	public bool InPosition { get; set; }

	/// <summary>
	/// 回零误差 (Bit16)
	/// </summary>
	public bool HomeError { get; set; }

	/// <summary>
	/// 回零完成 (Bit17)
	/// </summary>
	public bool Homed { get; set; }

	/// <summary>
	/// 目标到达 (Bit18)
	/// </summary>
	public bool Position_OK { get; set; }

	/// <summary>
	/// 原点开关 (Bit20)
	/// </summary>
	public bool OriginSwitch { get; set; }

	/// <summary>
	/// 掉线 (Bit24 OFFLINE)
	/// </summary>
	public bool Offline { get; set; }


	#region 其他状态属性

	/// <summary>
	/// 实际位置
	/// </summary>
	public double Actual_P { get; set; }

	/// <summary>
	/// 实际速度
	/// </summary>
	public double Actual_V { get; set; }

	/// <summary>
	/// 实际扭矩
	/// </summary>
	public double Actual_T { get; set; }

	/// <summary>
	/// 目标位置
	/// </summary>
	public double Target_P { get; set; }

	/// <summary>
	/// 目标速度
	/// </summary>
	public double Target_V { get; set; }

	/// <summary>
	/// 目标扭矩
	/// </summary>
	public double Target_T { get; set; }

	#endregion

	/// <summary>
	/// 就绪状态
	/// </summary>
	public bool Ready => !Offline && !ServoAlarm;

	/// <summary>
	/// 错误状态
	/// </summary>
	public bool Error => Offline || ServoAlarm || ForwardLimit || ReverseLimit || HomeError;
}